#include "rs232.h"



void
putch(char c)
{
	unsigned char	dly, bitno;

	bitno = 11;

	INIT_TX;
	TxData = 0;			/* start bit */
	bitno = 12;
	do {
		dly = DELAY(TX_OHEAD);	/* wait one bit time */
		do
			/* nix */ ;
		while(--dly);
		if(c & 1)
			TxData = 1;
		if(!(c & 1))
			TxData = 0;
		c = (c >> 1) | 0x80;
	} while(--bitno);
DelayUs(200);
}

void putstr(register const char *str)
{
	while((*str)!=0)
	{
	putch(*str);
        if (*str==13) putch(10);
        if (*str==10) putch(13);
	str++;
	}
}


char
getch(void)
{
 unsigned char	c, bitno, dly;

 INIT_RX;
 for(;;) {
          while(RxData)
 continue;	/* wait for start bit */
		dly = DELAY(3)/2;
		do
			/* nix */;
		while(--dly);
		if(RxData)
			continue;	/* twas just noise */
		bitno = 8;
		c = 0;
		do {
			dly = DELAY(RX_OHEAD);
			do
				/* nix */;
			while(--dly);
			c = (c >> 1) | (RxData << 7);
		} while(--bitno);
		return c;
	}
}

char
getche(void)
{
	char c;

	putch(c = getch());
	return c;
}

